package gui2.g3;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class ChatTableModel extends AbstractTableModel implements
		ChatModelListener {

	private List<ChatMessage> messages = new ArrayList<ChatMessage>();

	@Override
	public int getRowCount() {
		return messages.size();
	}

	@Override
	public int getColumnCount() {
		return 2;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		ChatMessage m = messages.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return m.getUsername();
		case 1:
			return m.getMsg();
		}
		return null;
	}

	@Override
	public void messageAdded(List<ChatMessage> allMessages) {
		messages.add(allMessages.get(allMessages.size()-1));
		fireTableDataChanged();

	}


}
